package group.sicher.lock.brain.lock;

import group.sicher.lock.Exception.MarsKeyBuilderException;
import group.sicher.lock.brain.MarsLockKey;
import group.sicher.lock.constant.MarsLockConstant;

import java.lang.reflect.Method;

/**
 * @description:
 * @author: aron
 * @date: 2019-08-05 17:01
 */
public abstract class MarsKeyLockAbstractor {

    protected String className;
    protected String methodName;
    protected Method realMethod;
    protected Object[] args;

    public MarsKeyLockAbstractor(String className, String methodName, Method realMethod, Object[] args) {
        this.className = className;
        this.methodName = methodName;
        this.realMethod = realMethod;
        this.args = args;
    }

    public String getSimpleClassName() {
        return this.className.split("\\.")[this.className.split("\\.").length - 1];
    }

    /**
     * 包装锁的key标记
     *
     * @param valTag
     * @return
     */
    public String wrapKeyTag(String valTag) {
        return getSimpleClassName() + MarsLockConstant.KEY_SPLIT_MARK + this.methodName
                + MarsLockConstant.KEY_SPLIT_MARK + valTag;
    }

    /**
     * 创建锁
     */
    public abstract MarsLockKey.Builder builder() throws MarsKeyBuilderException;


}
